package lcy.homework02;

/**
 * @ClassName: Rectangle
 * @Description: 长方形类
 * @author: 李春洋
 * @date: 2024/3/30 17:26
 * @Blog: https://
 */
public class Rectangle {
    Point leftTop;
    Point rightTop;
    Point leftFloor;
    Point rightFloor;

    Rectangle() {
        this.leftTop = new Point(0.0, 0.0);
        this.rightTop = new Point(1.0, 0.0);
        this.leftFloor = new Point(0.0, -1.0);
        this.rightFloor = new Point(1.0, -1.0);
    }

    Rectangle(double x1, double y1, double x2, double y2) {
        this.leftTop = new Point(x1, y1);
        this.rightTop = new Point(x2, y1);
        this.leftFloor = new Point(x1, y2);
        this.rightFloor = new Point(x2, y2);
    }

    Rectangle(Point p1, Point p2) {
        this.leftTop = p1;
        this.rightTop = new Point(p2.x, p1.y);
        this.leftFloor = new Point(p1.x, p2.y);
        this.rightFloor = p2;
    }

    Point getLeftTop() {
        return leftTop;
    }

    Point getLeftFloor() {
        return leftFloor;
    }

    Point getRightTop() {
        return rightTop;
    }

    Point getRightFloor() {
        return rightFloor;
    }

    double calculatePerimeter() {
        double width = Math.abs(rightTop.x - leftTop.x);
        double height = Math.abs(leftTop.y - leftFloor.y);
        return 2 * (width + height);
    }

    double calculateArea() {
        double width = Math.abs(rightTop.x - leftTop.x);
        double height = Math.abs(leftTop.y - leftFloor.y);
        return width * height;
    }
}
